'use strict';
const {getDefaultModelConfig} = require("../../utils/common");

module.exports = app => {
    const { INTEGER, BIGINT, DATE, TEXT } = app.Sequelize;
    const BiddingSupplier = app.model.define(
        'BiddingSupplier',
        {
            id: { type: BIGINT, primaryKey: true, autoIncrement: true },
            monthly_bidding_id: { type: BIGINT, allowNull: false, comment: '月度比价ID' },
            supplier_id: { type: BIGINT, allowNull: false, comment: '供应商ID' },
            status: { type: INTEGER, defaultValue: 1, comment: '状态 1:参与竞标 2:已提交报价 3:已入围 4:未入围' },
            submit_time: { type: DATE, comment: '报价提交时间' },
            remark: { type: TEXT, comment: '备注' },
            ...getDefaultModelConfig(app)
        },
        {
            tableName: 'bidding_supplier',
            timestamps: true,
            createdAt: 'create_time',
            updatedAt: 'update_time'
        }
    );
    BiddingSupplier.associate = function () {
        BiddingSupplier.belongsTo(app.model.Business.MonthlyBidding, { foreignKey: 'monthly_bidding_id', targetKey: 'id', as: 'monthlyBidding' });
        BiddingSupplier.belongsTo(app.model.Business.Supplier, { foreignKey: 'supplier_id', targetKey: 'id', as: 'supplier' });
        BiddingSupplier.hasMany(app.model.Business.SupplierQuote, { foreignKey: 'monthly_bidding_supplier_id', targetKey: 'id', as: 'supplierQuotes' });
    };
    return BiddingSupplier;
};
